#!/usr/bin/perl 

use warnings;
use strict;

my $name= $ARGV[0];
my $nucleoStart = int($ARGV[1]);
my $nucleoEnd = int($ARGV[2]);
my @ctFiles=();


my @arrayNucleoApp=("");

	my $line="";
	sum_zone_no_apareados(\$name,\$line,$nucleoStart,$nucleoEnd);

 print "$line\n";

# # #############################################################################
##############################################################################
sub sum_zone_no_apareados
{
	my ($namefile,$returnValue,$iniNucleo,$endNucleo)=@_;
	open (HANDLE, $$namefile) || die "can't opendir $namefile: $!";
	my $DIGITS="\(\\d{1,5}\)";
	my $PATTER="\^\\s+".$DIGITS."\\s+\(\\d{1,3}\)\\s+\\w{1}\$";		
	my $PATTESTRUCT="^\\s+\(\\d{1,3}\)\$";	
	my $addNotApp=0;
	my $nucleo=1;
	my $number_struct=0;
	while ( defined(local $_= <HANDLE>) && ($nucleo != $endNucleo))
	{
 	        if(m/$PATTER/)
		{
	  	 $nucleo=$1;
	  	  my $appare=$2;
   	  	  if($nucleo >= $iniNucleo)
 	    	   {
		     $addNotApp+=$appare;	
		   }	
	    	}elsif (m/$PATTESTRUCT/) 
		{
		 	$number_struct=$1;
		}
		 
	}
	
 close (HANDLE);
 if($endNucleo == 0 ){ $endNucleo=$nucleo;}
 my $zone= ($endNucleo-$iniNucleo+1) * $number_struct;
 my $output= ($addNotApp)/ $zone;
 $$returnValue="$$namefile\,$number_struct\,$addNotApp\,$output\n";
}
